package com.briup.srms.cms.web.controller;

import com.briup.srms.cms.bean.Category;
import com.briup.srms.cms.bean.extend.CategoryExtend;
import com.briup.srms.cms.service.ICategoryService;
import com.jacky.base.utils.Message;
import com.jacky.base.utils.MessageUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @program: 杰普基础管理系统
 * @description: 栏目管理的控制器类
 * @author: charles
 * @create: 2020-11-14 15:09
 **/
@Api(description="栏目相关接口")
@Validated
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private ICategoryService categoryService;

    @ApiOperation(value = "查询所有栏目树")
    @GetMapping("queryTree")
    public Message queryTree(){
        List<CategoryExtend> list = categoryService.queryTree();
        return MessageUtil.success(list);
    }

    @ApiOperation(value = "通过id删除")
    @GetMapping("deleteById")
    public Message deleteById(long id){
        categoryService.deleteById(id);
        return MessageUtil.success("删除成功");
    }

    @ApiOperation(value = "批量删除")
    @PostMapping("batchDelete")
    public Message batchDelete(long[] ids){
        categoryService.batchDelete(ids);
        return MessageUtil.success("删除成功");
    }

    @ApiOperation(value = "保存或更新")
    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(Category category){
        categoryService.saveOrUpdate(category);
        return MessageUtil.success("更新成功");
    }



}
